package com.ssy.lingxi.common.constant.manage;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 商城类型 - enum
 * @author fhj
 * @date 2020/12/03
 * @version 2.0.0
 */
public enum ShopTypeEnum {

    ENTERPRISE(1, "企业商城"),
    SCORE(2, "积分商城"),
    CHANNEL(3, "渠道商城"),
    CHANNEL_SELF(4, "渠道自有商城"),
    CHANNEL_SCORE(5, "渠道积分商城"),
    PURCHASE(6, "采购门户"),
    LOGISTICS(7, "物流服务门户"),
    PROCESS(8, "加工服务门户"),
    INFORMATION(9, "行情资讯");

    private final Integer code;

    ShopTypeEnum(Integer code, String name) {
        this.code = code;
    }

    public static String getNameByCode(Integer code) {
        ShopTypeEnum status = Arrays.stream(ShopTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return status == null ? "" : status.getName();
    }

    public static ShopTypeEnum parseCode(Integer code) {
        return Arrays.stream(ShopTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    /**
     * 判断是否为企业商城或渠道商城或渠道自有商城
     * @param code 商城类型
     */
    public static boolean checkEnterpriseOrChannelOrChannelSelf(Integer code) {
        return Stream.of(ENTERPRISE, CHANNEL, CHANNEL_SELF).anyMatch(o -> o.getCode().equals(code));
    }

    /**
     * 获取渠道商城和渠道自有商城
     */
    public static List<Integer> getChannelAndChannelSelf() {
        return Stream.of(CHANNEL.getCode(), CHANNEL_SELF.getCode()).collect(Collectors.toList());
    }

    /**
     * 判断是否为渠道商城或渠道自有商城
     * @param code 商城类型
     */
    public static boolean checkChannelOrChannelSelf(Integer code) {
        return Stream.of(CHANNEL, CHANNEL_SELF).anyMatch(o -> o.getCode().equals(code));
    }

    /**
     * 根据门户类型获取商城类型集合
     * @param doorType 门户类型 1.会员店铺 2.渠道门户 3.采购门户 4.物流门户 5.加工门户
     * */
    public static List<Integer> findShopTypeListByDoorType(Integer doorType) {
        if(doorType == 1) {
            return Stream.of(ENTERPRISE.code, SCORE.code).collect(Collectors.toList());
        }else if(doorType == 2) {
            return Stream.of(CHANNEL.code, CHANNEL_SELF.code, CHANNEL_SCORE.code).collect(Collectors.toList());
        }else if(doorType == 3) {
            return Stream.of(PURCHASE.code).collect(Collectors.toList());
        }else if(doorType == 4) {
            return Stream.of(LOGISTICS.code).collect(Collectors.toList());
        }else if(doorType == 5) {
            return Stream.of(PROCESS.code).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(),this.code);
    }
}
